<template>
    <view class="page">
        <view class="row">
            <view class="label">地址</view>
            <view class="content">
                <input v-model="state.address" readonly placeholder="请选择地址" />
            </view>
        </view>

        <view class="row">
            <view class="label">类型</view>
            <view class="content">
                <radio-group>
                    <radio value="buy" :checked="state.type === 'buy'">买</radio>
                    <radio value="sell" :checked="state.type === 'sell'">卖</radio>
                </radio-group>
            </view>
        </view>

        <view class="row">
            <view class="label">说明</view>
            <view class="content">
                <input v-model="state.message" readonly placeholder="请输入说明" />
            </view>
        </view>

        <view class="row">
            <view class="label">联系方式</view>
            <view class="content">
                <input v-model="state.contact" readonly type="number" maxlength="11" placeholder="请输入联系方式" />
            </view>
        </view>
    </view>
</template>

<script setup lang="ts">
import { onLoad } from "@dcloudio/uni-app";
import { reactive } from "vue";

const state = reactive({
    address: "", // 地址
    lat: 0, // 纬度
    lng: 0, // 经度
    message: "", // 说明
    contact: "", // 联系方式
    type: "buy", // 类型 buy-买 sell-卖
});

onLoad((query: any) => {
    console.log("query", query);

    uni.request({
        url: `http://localhost:3000/trades/${query.id}`,
        method: "GET",
        success: (res) => {
            console.log("res.data", res.data);
            // state.address = res.data.address
            // state = res.data;
            Object.assign(state, res.data);
        },
    });
});
</script>
